<?php

namespace App\Observers;

use App\Models\Goods;

class GoodsObserver
{
    /**
     * Handle the goods "created" event.
     *
     * @param  \App\Models\Goods  $goods
     * @return void
     */
    public function created(Goods $goods)
    {
        //
    }

    /**
     * Handle the goods "updated" event.
     *
     * @param  \App\Models\Goods  $goods
     * @return void
     */
    public function updated(Goods $goods)
    {
        //
    }

    /**
     * Handle the goods "deleted" event.
     *
     * @param  \App\Models\Goods  $goods
     * @return void
     */
    public function deleted(Goods $goods)
    {
//        商品表和货品表是一对多的关系,通过商品表中的模型关联方法product()将对应货品表中的相关记录删除掉
        $goods->product()->delete();
    }

    /**
     * Handle the goods "restored" event.
     *
     * @param  \App\Models\Goods  $goods
     * @return void
     */
    public function restored(Goods $goods)
    {
        //
    }

    /**
     * Handle the goods "force deleted" event.
     *
     * @param  \App\Models\Goods  $goods
     * @return void
     */
    public function forceDeleted(Goods $goods)
    {
        //
    }
}
